function f = func_l(l_sol,rb,erk,lambda,gamma,delta,sigma_rk)

rkhats_next = log ( rb * (1-1/l_sol) * ( 1+lambda*(1-gamma) ) - (1-delta) );
z_temp      = (rkhats_next - erk) / sigma_rk;
z_temp_log  = (erk + sigma_rk^2 - rkhats_next) / sigma_rk;

cdf = normcdf(z_temp);
pdf = normpdf(z_temp);
cdf_log = normcdf(z_temp_log);
        
f = rb - ( exp(erk + sigma_rk^2/2) * cdf_log / (1-cdf) + (1-delta) ...
              - lambda * ( rb^2 * (1-gamma) * (1+lambda*(1-gamma)) * (l_sol-1)/l_sol^2 ) ...
              / ( rb * (1-1/l_sol)  * (1+lambda*(1-gamma)) - 1+delta ) /sigma_rk * pdf/(1-cdf) );

end